{% extends 'myadmin/index.html' %}

{% block title %}
<title>后台-商品列表</title>
{% endblock %}

{% block content %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf" style="font-size: 26px;color: #3599d6;">商品列表</div></div>
                <div class="widget-body  am-fr">
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success">
                                        <a href="{% url 'myadmin_goods_add' %}" style="color: #fff">
                                            <i class="iconfont icon-add-s" style="font-size: 12px;"></i>新增</a>
                                    </button>                                 
                                    <button type="button" class="am-btn am-btn-default am-btn-secondary">
                                        <span class="am-icon-save"></span>保存</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-warning">
                                        <span class="am-icon-archive"></span>审核</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-danger">
                                        <span class="am-icon-trash-o"></span>删除</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <form>
                        <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                            <div class="am-form-group tpl-table-list-select">
                                <select name="types" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                                    <option value="title" {% if request.GET.types == 'username' %} selected {% endif %}>商品名</option>
                                    <option value="price" {% if request.GET.types == 'age' %} selected {% endif %}>单价</option>
                                    <option value="status" {% if request.GET.types == 'status' %} selected {% endif %}>状态</option>
                                    
                                </select>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                            <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                <input value="{{ request.GET.keywords }}" name="keywords" type="text" class="am-form-field ">
                                <span class="am-input-group-btn">
                                    <button id="search" class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"></button>
                                </span>
                            </div>
                        </div>
                    </form>
                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>主图</th>
                                    <th>商品名</th>
                                    <th>所属分类</th>
                                    <th>单价</th>
                                    <th>库存量</th>
                                    <th>点击量</th>
                                    <th>购买量</th>
                                    <th>状态</th>
                                    <th>添加时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for u in goodslist %}
                                <tr class="gradeX">
                                    <td class="am-text-middle">{{ u.id }}</td>
                                    <td class="am-text-middle">
                                        <img src="{{ u.pic_url }}" class="tpl-table-line-img" alt="">
                                    </td>
                                    <td class="am-text-middle">{{ u.title }}</td>
                                    <td class="am-text-middle">{{ u.cateid.name }}</td>
                                    <td class="am-text-middle">{{ u.price }}</td>
                                    <td class="am-text-middle">{{ u.store }}</td>
                                    <td class="am-text-middle">{{ u.clicknum }}</td>
                                    <td class="am-text-middle">{{ u.ordernum }}</td>
                                    <td class="am-text-middle">
                                        {% if u.status == 0 %}
                                            上架
                                        {% elif u.status == 1 %}
                                            热卖
                                        {% elif u.status == 2 %}
                                            下架
                                        {% endif %}
                                    </td>
                                    <td class="am-text-middle">{{ u.addtime }}</td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="{% url 'myadmin_goods_edit' %}?gid={{ u.id }}">
                                                <i class="am-icon-pencil"></i>编辑</a>
                                            <a href="{% url 'myadmin_goods_del' u.id %}" class="tpl-table-black-operation-del">
                                                <i class="am-icon-trash"></i>删除</a>
                                        </div>
                                    </td>
                                </tr>
                                {% endfor %}
                                <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                                {% load pagetag %}
                                {% showpages goodslist.paginator.num_pages request %}
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    // 给搜索按钮绑定单击事件
    $('#search').click(function(){
        // 获取选框的值
        var v = $('select[name=types]').val()
        // 判断类型
        if (v == 'price'){
            // 获取输入的关键字,检测是否正确
            var k = $('input[name=keywords]').val()
            var reg = /^(\d+|\d+\.\d+)-(\d+|\d+\.\d+)$/
            if (!reg.test(k)){
                alert('格式输入有误，正确格式：100-200')
                return false;
            }
        }
            
    })
</script>
{% endblock %}